package com.example.demo.controller;

import com.example.demo.entity.ClassroomEntity;
import com.example.demo.entity.StudyroomSeatEntity;
import com.example.demo.service.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * (Studyroomseat)表控制层
 *
 * @author makejava
 * @since 2021-10-12 15:31:20
 */
@Controller
public class StudyroomseatController {
    /**
     * 服务对象
     */
    @Autowired
    private StudyroomseatService studyroomseatService;
    @Autowired
    private ClassroomrentalService classroomrentalService;
    @Autowired
    private StudyroomService studyroomService;
    @Autowired
    private BuildingService buildingService;
    @Autowired
    private TimeService timeService;

    @RequestMapping("StudyroomseatList")
    public String StudyroomseatList(Model model){
        model.addAttribute("allBuilding",buildingService.queryBuildingAll());
        model.addAttribute("allTime",timeService.selectAllTime());
        return "studyRoomSet-list";
    }
    @RequestMapping("toaddStudyroomseat")
    public String addStudyroomseat(Model model){
        model.addAttribute("allBuilding",buildingService.queryBuildingAll());
        model.addAttribute("allStudentRoom",studyroomService.queryStudyroomAll());
        return "studentRoomSet-add";
    }
    @RequestMapping("addStudyroomset")
    @ResponseBody
    public int addStudyroomset(StudyroomSeatEntity studyroomSeatEntity){
        System.out.println(studyroomSeatEntity);
        int i = studyroomseatService.insertStudyroomseat(studyroomSeatEntity);
        if (i>0){
            return 1;
        }else{
            return 0;
        }


    }
    @RequestMapping("selectBySidStudyroomseat")
    @ResponseBody
    public List<StudyroomSeatEntity> selectBySidStudyroomseat(int sid,Model model){
        return studyroomseatService.selectBySidStudyroomseat(sid);
    }

    @RequestMapping("selectBysidNextSname")
    @ResponseBody
    public int selectBysidNextSname(int sid){
        return classroomrentalService.selectBysidNextSname(sid);
    }

}